﻿using System;

namespace Tzx.TUpdater.Entity
{
    /// <summary>
    /// 更新项目实体类
    /// </summary>
    internal class UpdateItem
    {
        #region 构造

        /// <summary>
        /// 
        /// </summary>
        internal UpdateItem()
        {
            
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="path"></param>
        /// <param name="ver"></param>
        internal UpdateItem(string path,string ver)
        {
            _ver = ver;
            _path = path;
        }

        #endregion

        #region 属性

        /// <summary>
        /// 
        /// </summary>
        internal int Index
        {
            get { return _index; }
            set { _index = value; }
        }
        private int _index;

        /// <summary>
        /// 
        /// </summary>
        internal int Progress
        {
            get { return _progress; }
            set { _progress = value; }
        }
        private int _progress;

        /// <summary>
        /// QUpdater_文件路径名称(服务器端)
        /// </summary>
        internal string Xml_Path
        {
            get { return _path; }
            set { _path = value; }
        }
        private string _path;

        /// <summary>
        /// QUpdater_文件版本
        /// </summary>
        internal string Xml_Ver
        {
            get { return _ver; }
            set { _ver = value; }
        }
        private string _ver;

        /// <summary>
        /// QUpdater_保存文件名(改名)
        /// </summary>
        internal string Xml_Desname
        {
            get { return _desname; }
            set { _desname = value; }
        }
        private string _desname;

        /// <summary>
        /// QUpdater_操作
        /// </summary>
        internal string Xml_Action
        {
            get { return _action; }
            set { _action = value; }
        }
        private string _action;

        /// <summary>
        /// QUpdater_快捷方式
        /// </summary>
        internal string Xml_Shortcut
        {
            get { return _shortcut; }
            set { _shortcut = value; }
        }
        private string _shortcut;

        #endregion

        #region 辅助方法

        /// <summary>
        /// 获得本地文件路径
        /// </summary>
        /// <returns></returns>
        private string GetLocalPath()
        {
            string path = string.Format("{0}", Xml_Path).Trim();
            string desname = string.Format("{0}", Xml_Desname).Trim();
            string localPath = desname.Length == 0 ? path : desname;
            return localPath;
        }

        /// <summary>
        /// 获得本地文件路径
        /// </summary>
        /// <returns></returns>
        public string GetLocalFullPathName()
        {
            string localFile = string.Format("{0}", GetLocalPath()).Trim();
            if (localFile.Length == 0)
            {
                return null;
            }

            //变量转换

            //本地路径
            localFile = localFile.Replace('/', '\\');
            return string.Format("{0}\\{1}",
                AppGlobal.ExeDirectory.TrimEnd('\\'),
                localFile.TrimStart('\\')
                );
        }

        /// <summary>
        /// 是否为删除动作
        /// </summary>
        /// <returns></returns>
        public bool IsActionDelete()
        {
            string action = string.Format("{0}", Xml_Action).Trim();
            return String.Compare(action, XmlConfig.Text_Node_File_Attr_ActionValue_Delete, StringComparison.InvariantCultureIgnoreCase) == 0;
        }

        #endregion

    }
}